package com.prjsystem.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.prjsystem.common.constant.CMSConstant;
import com.prjsystem.common.constant.MSGConstant;
import com.prjsystem.aop.AppTransactionManager;
import com.prjsystem.entity.UserInfo;
import com.prjsystem.service.TopMenuService;
import org.apache.log4j.Logger;

public class LoginAction extends ActionSupport {
    /**
	 * 
	 */
	private static final long serialVersionUID = -6662746972470407400L;
	private static Logger logger = Logger.getLogger(AppTransactionManager.class);
    private TopMenuService topMenuService;
	private UserInfo userInfo;
	private UserInfo us;
	private String ajaxResult; 
	
	public String init() {
		return SUCCESS;
	}
	
	public TopMenuService getTopMenuService() {
		return topMenuService;
	}

	public void setTopMenuService(TopMenuService topMenuService) {
		this.topMenuService = topMenuService;
	}

	public UserInfo getUserInfo() {
		return userInfo;
	}

	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}

	public String login() throws Exception{
		userInfo = topMenuService.getUserInfo(us);
		if (userInfo == null) {
			this.addFieldError(CMSConstant.NAME, getText(MSGConstant.MSG00001));
			return LOGIN;
		} else {
			ActionContext ctx = ActionContext.getContext();
			ctx.getSession().put(CMSConstant.USERINFO, userInfo);
			logger.debug(CMSConstant.LOGGERDEG);
			logger.info(CMSConstant.LOGGERINFO);
	        System.out.println(CMSConstant.LOGGERPRI);
		}
		return SUCCESS;
     }
	
	public String getAjaxResult() {
		return ajaxResult;
	}
	public void setAjaxResult(String ajaxResult) {
		this.ajaxResult = ajaxResult;
	}

	public UserInfo getUs() {
		return us;
	}

	public void setUs(UserInfo us) {
		this.us = us;
	}
}
